package com.lanqiao.companymanage.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanqiao.companymanage.mapper.StaffMessMapper;
import com.lanqiao.companymanage.entity.Dep;
import com.lanqiao.companymanage.service.StaffMessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author 何小棍
 * 部门信息管理与添加
 */
@Service
public class StaffMessServiceImpl extends ServiceImpl<StaffMessMapper,Dep> implements StaffMessService {
    @Autowired
    StaffMessMapper staffMessDao;

    /**
     * 分页查询
     * @param depPage
     * @return
     */
    @Override
    public Page<Dep> listPage(Page<Dep> depPage) {
        return staffMessDao.selectPage(depPage,null);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Dep selectById(Integer id) {
        Dep dep = staffMessDao.selectById(id);
        return dep;
    }

    /**
     * 部门信息添加
     * 名称、人数、工资系数
     * @param dep
     * @return
     */
    @Override
    public int addDep(Dep dep) {
        int i = staffMessDao.insert(dep);
        return i;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        // 删除部门
        int i = staffMessDao.deleteById(id);
        // 删除员工与部门的关联表
        staffMessDao.deleteUserTea(id);
        return i;
    }

    /**
     * 根据id修改
     * @param dep
     * @return
     */
    @Override
    public int updateMess(Dep dep) {
        int i = staffMessDao.updateById(dep);
        return i;
    }

    /**
     * 查询全部部门信息
     */
    @Override
    public List<Dep> selectAll() {
        return staffMessDao.selectList(null);
    }
}
